package com.example.aop.biz;

import org.aspectj.lang.JoinPoint;

import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * ClassName:SecurityAspect
 * Package:com.example.aop.biz
 * Description:
 *
 * @Author:ZhangXin
 * @Create:2023/5/11-9:32
 * @Version:v1.0
 */
//安全
@Component
@Aspect
public class SecurityAspect {

    @Pointcut("execution( * com.example.aop.biz..save*(..))")
    public void savePointcut(){}

    @Pointcut("execution( * com.example.aop.biz..delete*(..))")
    public void deletePointcut(){}

    @Pointcut("execution( * com.example.aop.biz..modify*(..))")
    public void modifyPointcut(){}

    @Pointcut("execution( * com.example.aop.biz..get*(..))")
    public void getPointcut(){}


    @Before("savePointcut()||deletePointcut()||modifyPointcut()||getPointcut()")
    public void afterReturningAdvice(JoinPoint joinPoint) {
        //系统时间
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss SSS");
        String nowTime = sdf.format(new Date());
        //输出日志信息
        System.out.println(nowTime + "张三:" + joinPoint.getSignature().getDeclaringTypeName() + "." + joinPoint.getSignature().getName());

    }

}
